package com.atguigu.zy.interview.juc.thread;

import java.util.*;

/**
 * @author: Administrator
 * @create 2023-08-31 7:42
 */
public class ContainerNotSafeDemo {
    public static void main(String[] args) {
        //List<Object> list = new Vector<>(); add方法加锁
        List<Object> list = Collections.synchronizedList(new ArrayList<>());
        for (int i = 1; i <= 30; i++) {
            new Thread(() -> {
                list.add(UUID.randomUUID().toString().substring(0, 8));
                System.out.println(list);
            }, String.valueOf(i)).start();
        }
        /**
         * 1、故障现象  java.util.ConcurrentModificationException
         * 2、导致原因
         * 3、解决方案
         * 1、Vector
         * 2、Collections.synchronizedList(new ArrayList<>()
         * 4、优化建议
         */
    }
}
